package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.administrator.text.R;
import java.util.List;
import entity.VideoMonitor;
import util.JumpActivityUtils;
import util.LogUtil;

/**
 * Created by liuxiaobin on 2017/2/14
 * 视频的适配器
 */

public class VideoMoitorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener{
    private LayoutInflater mLayoutInflater;
    private Context mContext;
    private List<VideoMonitor.CommBean> mCommBeen;     //公司内部区域
    private List<VideoMonitor.IndoorBean> mBeanList;  //公共区域
    private int mStandard,mPosition;

    public VideoMoitorAdapter(Context context,int standard,List<VideoMonitor.CommBean> commBeen,List<VideoMonitor.IndoorBean> beanList){
        this.mContext = context;
        this.mStandard = standard;
        this.mCommBeen = commBeen;
        this.mBeanList = beanList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        RecyclerView.ViewHolder holder = null;
        if(mStandard == 1){
            view = mLayoutInflater.inflate(R.layout.adapter_videomoitor, parent, false);
            holder = new VideoMoitorAdapter.CustomHolder(mContext,view);
            view.setOnClickListener(this);
        }else if(mStandard == 2){
            view = mLayoutInflater.inflate(R.layout.adapter_videomoitor, parent, false);
            holder = new VideoMoitorAdapter.CustomHolder1(mContext,view);
            view.setOnClickListener(this);
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LogUtil.eE("","position:   "+position);
         if(holder instanceof CustomHolder){
             LogUtil.eE("",""+mCommBeen.size());
             if(mCommBeen !=null && mCommBeen.size()>0){
                 ((VideoMoitorAdapter.CustomHolder)holder).mTextView.setText(mCommBeen.get(position).getName());
                /* BitmapUtil.newBitmap().getBitmap(mContext,"",((VideoMoitorAdapter.CustomHolder)holder).mIvImage,1,
                         HomeUtil.getHemeUtilNew().getDisplayImageOptions(true,R.mipmap.we_camera));*/
                 holder.itemView.setTag(position);
                 mPosition = position;
             }
         }else if(holder instanceof CustomHolder1){
             LogUtil.eE("",""+mBeanList.size());
            if(mBeanList !=null && mBeanList.size()>0){
                ((VideoMoitorAdapter.CustomHolder1)holder).mTextView.setText(mBeanList.get(position).getName());
            /*    BitmapUtil.newBitmap().getBitmap(mContext,"",((VideoMoitorAdapter.CustomHolder1)holder).mIvImage,1,
                        HomeUtil.getHemeUtilNew().getDisplayImageOptions(true,R.mipmap.we_camera));*/
                holder.itemView.setTag(position);
                mPosition = position;
            }
        }
    }

    @Override
    public int getItemCount() {
        if(mStandard == 1){
            return mCommBeen.size();
        }else if(mStandard == 2){
            return mBeanList.size();
        }
        return mStandard;
    }

    @Override
    public void onClick(View v) {
        int teg = (int) v.getTag();
        LogUtil.eE("",""+teg);
        if(mStandard == 1){
            JumpActivityUtils.getInstance().jumpVideo(mContext,mCommBeen.get(teg).getKey(),mCommBeen.get(teg).getValue());
        }else if(mStandard == 2) {
            JumpActivityUtils.getInstance().jumpWebView(mContext,mBeanList.get(teg).getUrl(),"视频监控");

        }
    }

    public static class CustomHolder extends RecyclerView.ViewHolder{

        ImageView mIvImage; //展示的图片
        TextView mTextView;

        public CustomHolder(Context context, View view) {
            super(view);
            mIvImage = (ImageView) view.findViewById(R.id.iv_videomoitor);
            mTextView = (TextView) view.findViewById(R.id.text_iv_videomoitor);
        }
    }

    public static class CustomHolder1 extends RecyclerView.ViewHolder{

        ImageView mIvImage; //展示的图片
        TextView mTextView;

        public CustomHolder1(Context context, View view) {
            super(view);
            mIvImage = (ImageView) view.findViewById(R.id.iv_videomoitor);
            mTextView = (TextView) view.findViewById(R.id.text_iv_videomoitor);
        }
    }
}
